import 'package:znmm/UI/utils/my_global.dart';

class CnUserModel {
  int id = 0;
  String email = "";
  String firstName = "";
  String lastName = "";
  String username = "";

  List<String> billingList = [];
  List<String> billingKeyList = [];

  List<String> shippingList = [];
  List<String> shippingKeyList = [];

  CnUserModel();

  CnUserModel.fromJson(Map<String, dynamic> json) {
    id = MyGlobal.checkNullOrZero(json["id"]);
    email = MyGlobal.checkNullOrEmpty(json["email"]);
    firstName = MyGlobal.checkNullOrEmpty(json["first_name"]);
    lastName = MyGlobal.checkNullOrEmpty(json["last_name"]);
    username = MyGlobal.checkNullOrEmpty(json["username"]);

    billingList.clear();
    var billJson = json["billing"];

    if (billJson != null) {
      List<String> keys = billJson.keys.toList(); // 获取所有键，转换为列表
      billingKeyList = keys;

      billingList.add(MyGlobal.checkNullOrEmpty(billJson["first_name"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["last_name"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["company"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["address_1"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["address_2"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["city"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["postcode"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["country"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["state"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["email"]));
      billingList.add(MyGlobal.checkNullOrEmpty(billJson["phone"]));
    }

    //////
    shippingList.clear();
    var shipJson = json["shipping"];
    if (shipJson != null) {
      List<String> keys = shipJson.keys.toList(); // 获取所有键，转换为列表
      shippingKeyList = keys;

      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["first_name"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["last_name"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["company"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["address_1"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["address_2"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["city"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["postcode"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["country"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["state"]));
      shippingList.add(MyGlobal.checkNullOrEmpty(shipJson["phone"]));
    }
  }
}
